<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>库存日报表</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<jsp:include page="${pageContext.request.contextPath }/resource_path.jsp" flush="true"/>
</head>
<body class="layui-anim layui-anim-up">
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a>
          <cite>库存日报表</cite>
        </a>
      </span>
    </div>
    <div class="x-body">
		<div class="layui-row">
			<div class="layui-form">
				<div class="layui-input-inline">
					<div class="layui-input-inline" style="width: 165px">
						<select  class="" name="keyword" id="customer_id" lay-filter="keyword">
							<option value="">--请选择供应商--</option>
							<c:forEach items="${allCustomerList }" var="customer">
								<option value="${customer.id}">${customer.customer_name }</option>
							</c:forEach>
						</select>
					</div>

					<div class="layui-input-inline" style="width: 150px">
						<input class="layui-input" id="keyword2" placeholder="请输入SAP/QAD" style="width: 150px">
					</div>

					<div class="layui-input-inline" style="width: 165px">
						<input type="text" class="layui-input" id="test1" style="display: inline; width: 180px; margin-left: 10px">
						<%--<input class="layui-input" name="date" id="date" placeholder="请输入日期" autocomplete="off" style="display: inline; width: 180px; margin-left: 10px">--%>
					</div>

					<%--<div class="layui-input-inline" style="width: 150px">
						<input type="text" class="layui-input" placeholder="yyyy-MM-dd HH:mm:ss" id="test2" style="display: inline; width: 150px; margin-left: 10px">
					</div>--%>

					<div class="layui-input-inline" style="width: 30px"	>
						<input type="hidden" id="dateTime">
						<input type="hidden" id="dateTime2">
					</div>

					<button class="layui-btn layui-btn-normal" data-type="reload"><i class="layui-icon layui-icon-search"></i>检索</button>		
					<button class="layui-btn layui-btn-danger" id="export"><i class="layui-icon layui-icon-upload"></i>导出</button> 
				</div>

			</div>
		</div>
	  <table class="layui-hide" id="tableList" lay-filter="tableList"></table>
	</div>
	<!-- 弹框1 -->
	<div id="div1" hidden="hidden">
		<div style="width: 100%;">
			<table id="table1" lay-filter="table1">
			</table>
		</div>
	</div>
	<!-- 弹框2 -->
	<div id="div2" hidden="hidden">
		<div style="width: 100%;">
			<table id="table2" lay-filter="table2">
			</table>
		</div>
	</div>
	<!-- 弹框3 -->
	<div id="div3" hidden="hidden">
		<div style="width: 100%;">
			<table id="table3" lay-filter="table3">
			</table>
		</div>
	</div>
	<!-- 弹框1 -->
	<div id="div4" hidden="hidden">
		<div style="width: 100%;">
			<table id="table4" lay-filter="table4">
			</table>
		</div>
	</div>

	<script>
		$(document).ready(function () {
			var time = new Date();
			var day = ("0" + time.getDate()).slice(-2);
			var month = ("0" + (time.getMonth() + 1)).slice(-2);
			var today = time.getFullYear() + "-" + (month) + "-" + (day);
			$('#dateTime').val(today);
			$('#dateTime2').val(today);
		})




	</script>
	<script type="text/javascript">

		layui.use('laydate', function(){
			var laydate = layui.laydate;

			//执行一个laydate实例
			laydate.render({
				elem: '#test1' ,//指定元素
				value: new Date(),
				type:'date',
				done:function(value, date, endDate) {
					$('#dateTime').val(value);
				}
			});
			laydate.render({
				elem: '#test2' ,//指定元素
				value: new Date(),
				type: 'datetime',
				done:function(value, date, endDate) {
					$('#dateTime2').val(value);
				}
			});
		});


		$(document).ready(function () {

			var time = new Date();
			var day = ("0" + time.getDate()).slice(-2);
			var month = ("0" + (time.getMonth() + 1)).slice(-2);
			var today = time.getFullYear() + "-" + (month) + "-" + (day);
			$('#dateTime').val(today);
		});


        var table;
		layui.use(['table','layer','upload','form','laydate'], function(){
			table = layui.table;
			var layer = layui.layer;
			var form = layui.form;
			var laydate = layui.laydate;
			//执行一个laydate实例
			laydate.render({
				elem: '#date', //指定元素
				type: 'date',
				value: new Date(),
				format: 'yyyy-MM-DD', //自动生成的时间格式   
				btns: ['now', 'confirm']
			});
			
			var $ = layui.jquery, active = {
				reload:function () {

					var date = $('#dateTime').val();
					//产品名称
					var keyword2 = $.trim($("#keyword2").val());
					var customer_id = $("#customer_id").val();
					var dateTime2 = $('#dateTime2').val();
					table.reload('tableList',{
						method:'get'
						,where:{
							'ma_id':keyword2
							,'date':date
							,'customer_id':customer_id
							,'dateTime2':dateTime2
						}
						,page: {
							curr: 1//重新从第 1 页开始
						}
					});
				}
			}
			$('.layui-btn').on('click', function(){
				var type = $(this).data('type');
				active[type] ? active[type].call(this) : '';
			});
			$("#date").val(curentMonth())
			$("#type").val('month')
			$('#type').attr("disabled",true)
			$("#customer_id").val('${customer_id}')
			$('#customer_id').attr("disabled",true)
			var date = $('#dateTime').val();
			//产品名称
			var keyword2 = $.trim($("#keyword2").val());
			var customer_id = $("#customer_id").val();
			var dateTime2 = $('#dateTime2').val();
            table.render({
				elem: '#tableList'
				,where:{
					'ma_id':keyword2
					,'date':date
					,'customer_id':customer_id
					,'dateTime2':dateTime2
				}
                ,url:'${pageContext.request.contextPath }/reportForm/getDateBalance.do'
				,toolbar: '#toolbar'
				,title: 'machineList'
				,limits:[10,20,30]
                //,defaultToolbar:['filter', 'print']
				,request: {   //如果无需自定义请求参数，可不加该参数
	                pageName: 'page' //页码的参数名称，默认：page
	                ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
	            }
	            ,response: {   //如果无需自定义数据响应名称，可不加该参数
	                countName: 'total' //规定数据总数的字段名称，默认：count
	                ,dataName: 'rows' //规定数据列表的字段名称，默认：data
	            },
                page:true
				,cols: [
		                [{
		                /*     type: 'checkbox',
		                    fixed: 'left'
		                }, { */
		                	field:'uid',
		                	title:'序号', 
		                	sort: true,
		                	width: 60,
		                	type:'numbers',
		                	align:'center'
		                }, {
							field: 'customerName',
							title: '供应商',
							width: 130,
		                	align:'center'
						},{
							field: 'createDate',
							title: '时间',
							width: 110,
		                	align:'center'
						}, {
		                    field: 'materielName',
		                    title: '零件名称',
		                    align:'center',


		                } , {
		                    field: 'materielNum',
		                    title: 'SAP/QAD',
		                    align:'center',
		                    width: 130,

		                }, {
		                    field: 'yestdayNum',
		                    title: '昨日结存',
		                    align:'center',
		                    width: 100,
		                }, {
		                    field: 'thisMonthAdd',
		                    title: '当日入库',
		                    align:'center',
		                    width: 100,
							event: 'tankuang1',
							templet: function (row){

								var value="";

								if (row.thisMonthAdd != 0) {
									value = '<div style="color: red;">'+row.thisMonthAdd+'</div>';
								}else {
									value = 0;
								}
								return value;
							}
		                }, {
							field: 'thisMonthTuiHui',
							title: '当日退回',
							align:'center',
							width: 100,
							event: 'tankuang3',
							templet: function (row){
								var value="";
								if (row.thisMonthTuiHui != 0) {
									value = '<div style="color: red;">'+row.thisMonthTuiHui+'</div>';
								}else {
									value = 0;
								}
								return value;
							}
						},{
		                    field: 'thisMonthReduce',
		                    title: '当日出库',
		                    align:'center',
		                    width: 100,
							event: 'tankuang2',
							templet: function (row){
								var value="";
								if (row.thisMonthReduce != 0) {
									value = '<div style="color: red;">'+row.thisMonthReduce+'</div>';
								} else {
									value = 0;
								}
								return value;
							}
		                }, {
		                    field: 'thisMonthReturn',
		                    title: '当日退库',
		                    align:'center',
		                    width: 100,
		                    event: 'tankuang4',
							templet: function (row){
								var value="";
								if (row.thisMonthReturn != 0) {
									value = '<div style="color: red;">'+row.thisMonthReturn+'</div>';
								} else {
									value = 0;
								}
								return value;
							}

		                }, {
		                    field: 'geLiBalance',
		                    title: '当日不良',
		                    align:'center',
		                    width: 100/* ,
                            templet: function (row){
		                        return 0;
                            } */
		                }, {
		                    field: 'num7',
		                    title: '当日库存',
		                    align:'center',
		                    width: 100,
							templet: function (row){
								var value = "";
								if(null != row.geLiBalance){
									value = row.thisMonthAdd - row.thisMonthReduce + row.yestdayNum - row.thisMonthReturn+row.thisMonthTuiHui;
								}

								if (value > 0) {
									return value
								} else {
									return 0
								}
							}
		                }, {
		                    field: 'num8',
		                    title: '当日良品',
		                    align:'center',
		                    width: 150,
                            templet: function (row){
                                var value = "";
                                if(null != row.geLiBalance){
                                    value = row.thisMonthAdd - row.thisMonthReduce + row.yestdayNum - row.thisMonthReturn - row.geLiBalance + row.thisMonthTuiHui;
                                }
                                return value;
                            }
		                },/*  {
		                    field: 'num9',
		                    title: '盘点数量',
		                    align:'center',
		                    width: 150,
		                }, {
		                    field: 'num10',
		                    title: '差异',
		                    align:'center',
		                    width: 100,
                            templet: function (row){
		                        return 0;
                            }
		                }, {
		                    field: 'kw',
		                    title: '库位',
		                    align:'center',
		                    width: 100,
		                }, {
		                    field: 'upperValue',
		                    title: '上限',
                            width: 100
		                }, {
		                    field: 'lowerValue',
		                    title: '下限',
		                    align:'center',
		                    width: 100
		                }*/
		                ]
		               ]
				,done : function(res, curr, count){
	                $('th').css({
	                    'background-color': '#009688', 'color': '#fff','font-weight':'bold',
	                })
				}
			});


            $("#export").click(function(){
           
            	var date = $('#dateTime').val();
    		    var keyword2 = $.trim($("#keyword2").val());
    			var customer_id = $("#customer_id").val();
    			var dateTime2 = $('#dateTime2').val();
    			window.location.href="${pageContext.request.contextPath }/reportForm/ExportallDateBalance.do?date="+date+"&ma_id="+keyword2+"&customer_id="+customer_id+"&dateTime2="+dateTime2;
           
            })

          //监听单元格事件
            table.on('tool(tableList)', function(obj){
              var materiaId = obj.data.materiaId;
              for (var i = 1; i <= 4; i++) {
	              if(obj.event === ('tankuang'+i)){
	            	  tankuang(i,materiaId)
	            	  break;
	              }
			  }

            });


			//获取当前日期
		   	function tankuang(type,materiaId) {
				var divID  = "div"+type

				var dateTime = $('#dateTime').val();

				var cols = [];


				var cols1 = [{field:'uid',title:'序号',sort: true,width: 60,type:'numbers',align:'center'
				},{field: 'volume',title: '供应商',width: 100

				}, {field: 'brevity_num',title: '单号',align:'center',width: 150
				}, {field: 'materiel_name',title: '零件名称',align:'center'
				}, {field: 'materiel_num',title: 'SAP/QAD',align:'center',width: 110}
				,{field: 'unit',title: '入库人',align:'center',width: 100}
				,{field: 'out_date',title: '时间',width: 120},
                    {field: 'packing_quantity',title: '数量',width: 120}]

				var cols2 = [
					{field:'uid',title:'序号',sort: true,width: 60,type:'numbers',align:'center'
					}, {field: 'volume',title: '供应商',align:'center',width: 150,
					}, {field: 'brevity_num',title: '单号',align:'center'
					}, {field: 'materiel_name',title: '零件名称',align:'center',width: 150,
					}, {field: 'materiel_num',title: 'SAP/QAD',width: 150,align:'center'
					/*}, {field: 'unit',title: '出库人员',align:'center',width: 100,*/
					}, {field: 'out_date',title: '出库时间',align:'center',width: 120,}
                    ,{field: 'packing_quantity',title: '数量',align:'center',width: 80,}
					]


				var cols3 = [{field:'uid',title:'序号',sort: true,width: 60,type:'numbers',align:'center'
				},{field: 'volume',title: '供应商',width: 100

				}, {field: 'brevity_num',title: '单号',align:'center',width: 150
				}, {field: 'materiel_name',title: '零件名称',align:'center'
				}, {field: 'materiel_num',title: 'SAP/QAD',align:'center',width: 110}
					,{field: 'unit',title: '入库人',align:'center',width: 100}
					,{field: 'out_date',title: '时间',width: 120},
					{field: 'packing_quantity',title: '数量',width: 120}]

				var cols4 = [{
						field:'uid',title:'序号',sort: true,width: 60,type:'numbers',align:'center'
					} ,{field: 'volume',title: '供应商',align:'center',width: 100,
					}, {field: 'brevity_num',title: '单号',align:'center',width: 150,
					} ,{field: 'materiel_name',title: '零件名称',align:'center',
					}, {field: 'materiel_num',title: 'SAP/QAD',align:'center',width: 150,
					}, {field: 'code_rule', title: '退库原因', align:'center', width: 100,
					}, {field: 'unit', title: '退库人员', align:'center', width: 100,
					}, {field: 'out_date', title: '退库时间', align:'center', width: 120,}
                    ,{field: 'packing_quantity',title: '数量',align:'center',width: 80,}
					]

				var title = "库存日报表-入库"
				if(type == 1){
					title = "库存日报表-入库"

					cols = cols1
				}else if(type == 2){
					title = "库存日报表-出库"
					cols = cols2
				}else if(type == 3){
					title = "库存日报表-退回"
					cols = cols3
				}else if(type == 4){
					title = "库存日报表-退库"
					cols = cols4
				}

				layer.open({
					type: 1,
					area: ['63%', '83%'],
					title : title,
					shadeClose: true,
					offset: '10%',
					maxmin : false,
					content : '<div><table id="templateTable"></table></div>',
					success: function(){

						table.render({
							elem: '#templateTable'
							,url:'${pageContext.request.contextPath }/reportForm/getReceiveDetail/'+type+'.do?materiaId='+materiaId+'&dateTime='+$('#dateTime').val()
							,title: 'machineList'
							,limits:[10,20,30]
							,page:true
							,request: {
								pageName: 'page'
								,limitName: 'pageSize'
							}
							,response: {
								countName: 'total'
								,dataName: 'rows'
							}
							,cols: [cols]
							,done : function(){
								$('th').css({
									'background-color': '#009688', 'color': '#fff','font-weight':'bold',
								})
							}
						});



					}
				});
		   	}
		});
		//获取当前日期
	   	function curentMonth() {
	   		var now=new Date();
	   		var year = now.getFullYear();       //年
	   	    var month = now.getMonth() + 1;     //月
	   	    var day = now.getDate();            //日
	   	    var time=year+"-"+add0(month);
	   		return time;
	   	}
	   	function add0(m){return m<10?'0'+m:m }
		toastrStyle()





	</script>
</body>
</html>
